﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ZGLXM.ErrorCode;
using ZGLXM.Writh.Api.Applicantion.Command.Login;
using ZGLXM.Writh.Api.Utils;

namespace ZGLXM.Writh.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class LoginController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly SmsClientFactory smsClientFactory;

        public LoginController(IMediator mediator, SmsClientFactory smsClientFactory)
        {
            this.mediator = mediator;
            this.smsClientFactory = smsClientFactory;
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult> Login([FromQuery]LoginCommand param)
        {
            return await mediator.Send(param);
        }

        /// <summary>
        /// 发送短信
        /// </summary>
        [HttpGet]
        public void SendSms()
        {
            smsClientFactory.SendSms("17745191384", "{\"code\":\"1234\"}", "阿里云短信测试", "SMS_154950909");
        }
    } 
}
